<template>
	<div >
		<el-dialog v-model="isShowDialog" :title="props.title" :width="700" draggable="">
			<el-form :model="ruleForm" ref="ruleFormRef" size="default" label-width="100px" :rules="rules">
				<el-row :gutter="35">
				
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
			              <el-form-item label="控制叉">
							<el-select v-model="ruleForm.fork"  >
						    <el-option
						      v-for="item in options"
						      :key="item.value"
						      :label="item.label"
						      :value="item.value"
						    />
						  </el-select>
			              </el-form-item>
			              </el-col>
         <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
			              <el-form-item label="控制类型">
							<el-select v-model="ruleForm.command"  >
						    <el-option
						      v-for="item in commands"
						      :key="item.value"
						      :label="item.label"
						      :value="item.value"
						    />
						  </el-select>
			              </el-form-item>
			              </el-col>

                     
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="堆垛机编号" prop="groupNumber">
							<el-input v-model="ruleForm.num" placeholder="堆垛机编号" clearable />
							
						</el-form-item>
						
					</el-col>
                   
                 
                    <el-col  :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="排" prop="toBank">
							<el-input v-model="ruleForm.z" placeholder="排" clearable />							
						</el-form-item>						
					</el-col>
                    <el-col  :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="列" prop="toBay">
							<el-input v-model="ruleForm.x" placeholder="列" clearable />							
						</el-form-item>						
					</el-col>
                    <el-col  :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="层" prop="toLevel">
							<el-input v-model="ruleForm.y" placeholder="层" clearable />							
						</el-form-item>						
					</el-col>

          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="任务号" prop="jobNumber">
							<el-input v-model="ruleForm.task" placeholder="任务号" clearable />
							
						</el-form-item>
						
					</el-col>


                    <el-col v-if="ruleForm.fork==3" :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="任务号2" prop="task2">
							<el-input v-model="ruleForm.task2" placeholder="任务号2" clearable />							
						</el-form-item>						
					</el-col>
        

					
					
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="cancel" size="default">取 消</el-button>
                    <el-button @click="reset" size="default">复 位</el-button>
                    <el-button @click="run" size="default">启 动</el-button>
                    <el-button @click="stop" size="default">停 止</el-button>
                    <el-button @click="deleteTask" size="default">删除任务</el-button>
					<el-button type="primary" @click="submit" size="default">确 定</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>

<script lang="ts" setup>
	import { ref,onMounted } from "vue";
	import { ElMessage } from "element-plus";
	import type { FormRules } from "element-plus";
	import { WriteSc } from '/@/api/main/grpcServer';
	//父级传递来的参数
	var props = defineProps({
	title: {
	type: String,
	default: "",
	},
	});
	//父级传递来的函数，用于回调
	const emit = defineEmits(["reloadTable"]);
	const ruleFormRef = ref();
	const isShowDialog = ref(false);
	const ruleForm = ref<any>({});
		//自行删除非必填规则
		const rules = ref<FormRules>({
  
  task: [{required: true, message: '任务号！', trigger: 'blur'}],
  fork: [{required: true, message: '选择叉！', trigger: 'blur'}],
  command: [{required: true, message: '控制类型！', trigger: 'blur'}],
  num: [{required: true, message: '编号！', trigger: 'blur'}]
  
});

const options = [
  {
    value: 1,
    label: '前叉',
  },
  {
    value: 2,
    label: '后叉',
  },
  {
    value: 3,
    label: '双叉',
  } 
];

const commands = [
  {
    value: 1,
    label: '取货',
  },
  {
    value: 2,
    label: '放货',
  }
  
];

// 打开弹窗
const openDialog = (row: any) => {
  ruleForm.value = JSON.parse(JSON.stringify(row));
  isShowDialog.value = true;
};

// 关闭弹窗
const closeDialog = () => {
  emit("reloadTable");
  isShowDialog.value = false;
};

// 取消
const cancel = () => {
  isShowDialog.value = false;
};
// 复位
const reset = async() => {
  let data={
    
   
    
  };
  await WriteSc(data);
  ElMessage({
        message: `操作成功`,
        type: "success",
      });
 
};
// 启动
const run = async() => {
    let data={
   
  };
  await WriteSc(data);
  ElMessage({
        message: `操作成功`,
        type: "success",
      });
};
// 停止
const stop = async() => {
    let data={
    
  };
  await WriteSc(data);
  ElMessage({
        message: `操作成功`,
        type: "success",
      });
};
// 删除任务
const deleteTask = async() => {
    let data={
    
  };
  await WriteSc(data);
  ElMessage({
        message: `删除任务`,
        type: "success",
      });
};

// 提交
const submit = async () => {
  ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
    if (isValid) {
      let values = ruleForm.value;
      await WriteSc(values);
      ElMessage({
        message: `提交成功`,
        type: "success",
      });
    } else {
      ElMessage({
        message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
        type: "error",
      });
    }
  });
};





// 页面加载时
onMounted(async () => {
});

//将属性或者函数暴露给父组件
defineExpose({ openDialog });
</script>




